/**
 * Copyright 2014,Peak Tai 台俊峰(taijunfeng_it@sina.com).
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * 		http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cenluan;

import java.io.IOException;

import com.cenluan.ext.jfinal.PkController;
import com.cenluan.login.ClearLoginInterceptor;
import com.jfinal.kit.HttpKit;

/**
 * 登录
 * 
 * @author peak
 * 
 */
@ClearLoginInterceptor
public class IndexController extends PkController {
	/**
	 * 首页
	 */
	public void index() {

	}

	/**
	 * 关于网站
	 */
	public void about() {

	}

	/**
	 * 跨域访问，把要访问的地址用参数传入，服务器端去请求后把结果返回，参加说明：<br>
	 * url:请求的地址，只支持get请求，参数都放在url里<br>
	 * type:要返回的数据类型，html,text,json三个可选，默认是json
	 * 
	 * @throws IOException
	 */
	public void cross() throws IOException {
		String url = getPara("url");
		String type = getPara("type", "json");
		String result = HttpKit.get(url);
		if ("json".equals(type)) {
			renderJson(result);
			return;
		}
		if ("text".equals(type)) {
			renderText(result);
			return;
		}
		if ("html".equals(type)) {
			renderHtml(result);
		}
	}
}
